@extends('layout.adminlayout')
@section('css')
<script src="/admin/js/metisMenu.min.js"></script>
<script src="/admin/js/custom.js"></script>
<link href="/admin/css/custom.css" rel="stylesheet">
@endsection
@section('content')
<div class="tables">
	<div class="table-responsive bs-example widget-shadow">
		<h4>待审批列表 :</h4>
		<table class="table table-bordered">
			{{csrf_field()}}
			<thead>
 				<tr>
					<th style="text-align: center">待审批编号</th>
					<th style="text-align: center">代理商名称</th>
					<th style="text-align: center">联系人</th>
					<th style="text-align: center">手机号</th>
					<th style="text-align: center">状态</th>
					<th style="text-align: center">操作</th>
				</tr>
			</thead>
			<tbody>
			@if(!null==$data)
				@foreach($data as $v)
					<tr>
						<th scope="row" style="text-align: center">{{$v['id']}}</th>
						<td>{!! $v['agent_name'] !!}</td>
						<td style="text-align: center">{{$v['linkman']}}</td>
						<td style="text-align: center">{{$v['phone']}}</td>
						<td style="text-align: center">
							@if($v['status'] == 0)
								待审批
							@elseif($v['status'] == 1)
								审批通过
							@elseif($v['status'] == 2)
								审批未通过
							@endif
						</td>
						<td style="text-align: center" id="operate_{{$v['id']}}">
							@if($v['status'] == 0)
								<a href="javascript:void (0)" onclick="agree({{$v['id']}})">通过</a>&nbsp;|&nbsp;<a href="javascript:void (0)" onclick="disagree({{$v['id']}})">不通过</a>
							@else
								<span>已完成操作</span>
							@endif
						</td>
					</tr>
				@endforeach
			@endif
			</tbody> 
		</table>
	</div>
</div>
<script>
	//同意
    function agree($approveId) {
        $.ajax({
            type:'post',
            url:"/admin/agent/agree",
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'approveId':$approveId
            },
            dataType:'json',
            success:function (data) {
            }
        })
        $('#operate_'+$approveId).empty();
		$('#operate_'+$approveId).append('<span>已完成操作</span>');
    }

    //不同意
	function disagree($approveId){
        $.ajax({
            type:'post',
            url:"/admin/agent/disagree",
            async:false,
            data:{
                "_token": $("input[name=_token]").val(),
                'approveId':$approveId
            },
            dataType:'json',
            success:function (data) {
            }
        })
        $('#operate_'+$approveId).empty();
        $('#operate_'+$approveId).append('<span>已完成操作</span>');
	}
</script>
@endsection

